syntax = "proto3";

package spqr;

option go_package = "spqr/proto";

message DistributionKeyEntry {
  string column = 1;
  string hashFunction = 2;
}

message DistributedRelation {
  string name = 1;
  repeated DistributionKeyEntry distributionKey = 2;
}

message Distribution {
  string id = 1;
  repeated string ColumnTypes = 2;
  repeated DistributedRelation relations = 3;
}

message CreateDistributionRequest{
  repeated Distribution distributions = 1;
}

message CreateDistributionReply{}

message ListDistributionsRequest{}

message ListDistributionsReply {
  repeated Distribution distributions = 1;
}

message DropDistributionRequest {
  repeated string ids = 1;
}

message DropDistributionReply{}

message AlterDistributionAttachRequest{
  string id = 1;
  repeated string ColumnNames = 2;
  repeated DistributedRelation relations = 3;
}

message AlterDistributionAttachReply{}

message AlterDistributionDetachRequest{
  string id = 1;
  repeated string relNames = 2;
}

message AlterDistributionDetachReply{}

message GetDistributionRequest{
  string id = 1;
}

message GetDistributionReply {
  Distribution distribution = 1;
}

message GetRelationDistributionRequest {
  string id = 1;
}

message GetRelationDistributionReply {
  Distribution distribution = 1;
}

service DistributionService {
  rpc CreateDistribution(CreateDistributionRequest) returns (CreateDistributionReply) {}
  rpc DropDistribution(DropDistributionRequest) returns (DropDistributionReply) {}
  rpc ListDistributions(ListDistributionsRequest) returns (ListDistributionsReply) {}

  rpc AlterDistributionAttach(AlterDistributionAttachRequest) returns (AlterDistributionAttachReply) {}
  rpc AlterDistributionDetach(AlterDistributionDetachRequest) returns (AlterDistributionDetachReply) {}

  rpc GetDistribution(GetDistributionRequest) returns (GetDistributionReply) {}

  rpc GetRelationDistribution(GetRelationDistributionRequest) returns (GetRelationDistributionReply) {}
}
